// /////////////////////////////////////////////////////////////////////////////
//
// Name:            ReferenceCounted.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the ReferenceCounted class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __REFERENCECOUNTED_H__
#define __REFERENCECOUNTED_H__

// Include files
#include "../dependencies.h"


// ReferenceCounted class
//! This class provides reference counting through the methods grab() and drop().
//! Most objects with the framework are derived from ReferenceCounted, and so they
//! are reference counted.
//!
//! When you create an object within the framework, calling a method which starts
//! with 'create', an object is created, and you get a pointer to the new object.
//! If you no longer need the object, you have to call drop(). This will destroy
//! the object, if grab() was not called in another part of you program, because
//! this part still needs the object. Note, that you only need to call drop() to
//! the object, if you created it, and the method had a 'create' in it.
//!
//! @note Adapted from the Irrlicht API documentation.
class ReferenceCounted
{
public:

    // Initialisation and deinitialisation
    //! Constructor
    ReferenceCounted();
    //! Deconstructor
    virtual ~ReferenceCounted();

    // Public methods
    //! Increases the reference counter.
    virtual void grab();
    //! Decreases the reference counter.
    virtual void drop();

    //! Gets the reference count.
    s32 getReferenceCount();

private:

    // Private members
    s32 mRefCount;
};

#endif
